<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Cart;
class CartController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $addcarts = [
            1 => ['id'=>1,'name'=>'风景1','price'=>10,'des'=>'好分光'],
            2 => ['id'=>2,'name'=>'风景2','price'=>20,'des'=>'坏风光'],
            3 => ['id'=>3,'name'=>'风景3','price'=>30,'des'=>'哈哈哈'],
        ];
        return view('cart.index',['addcarts'=>$addcarts]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $addcarts = [
            1 => ['id'=>1,'name'=>'风景1','price'=>10,'des'=>'好分光'],
            2 => ['id'=>2,'name'=>'风景2','price'=>20,'des'=>'坏风光'],
            3 => ['id'=>3,'name'=>'风景3','price'=>30,'des'=>'哈哈哈'],
        ];
        $addcart = $addcarts[$id];
        // var_dump($addcart);die;
        Cart::add($addcart['id'],$addcart['name'],1,$addcart['price']);
        // dd(Cart::content());
       return redirect()->route('addcart.edit');
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit()
    {
        $carts = Cart::content();

        $count = Cart::count();

        $total = Cart::subtotal();

        $tax = Cart::tax();
        return view('cart.addcart',['carts'=>$carts,'count'=>$count,'total'=>$total,'tax'=>$tax]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy()
    {
        
    }
}
